home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7683 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: system() & error detection
  5. Date: 26 Feb 1996 13:07:48 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4gt7f4INNt1j@keats.ugrad.cs.ubc.ca>
  8. References: <4gt24g$dba@ncar.ucar.edu>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4gt24g$dba@ncar.ucar.edu>,
  12. James Adams <jadams@sage.cgd.ucar.edu> wrote:
  13.  >Hello,
  14.  >
  15.  >        I am attempting to use the system() call in order to have a
  16.  >user-specified command execute in my program.
  17.  >
  18.  >        I am wondering how I can check whether or not the command has
  19.  >completed successfully ?  I don't want the program to continue if the
  20.  >call I make from system() produces some sort of error.  I'd like to be
  21.  >able to do something like the following:
  22.  >
  23.  >        result = system(command);
  24.  >        if (result == ERROR)
  25.  >          exit(0);
  26.  >
  27.  >Is there anyway to do this ?  Should I be using something other than
  28.  >system() ?
  29.  
  30. Try one of the member of the ``exec'' family of functions. These are defined by
  31. the POSIX.1 standard, not ISO/ANSI C.
  32.  
  33. Exec lets you get the return value. It is also more secure, since system() can
  34. be exploited in ways which violate system security.  If you are programming on
  35. a UNIX system, go to comp.unix.programmer and read their FAQ's. This is likely
  36. to be addressed.
  37. -- 
  38.  
  39.